package restful_apis.semantic_computing;

import com.fasterxml.jackson.databind.JsonNode;
import common.helper.json.JavaToJsonString;
import org.springframework.stereotype.Component;
import restful_apis.common.MediaTypes;
import semantic_compute.entity_linking.yago_linker.YagoQueryEntityLinker;
import semantic_compute.entity_linking.yago_linker.YagoTextsEntityLinker;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

/**
 * Created by julianzliu on 5/6/2017.
 */



@Path("/semantic")
@Produces(MediaTypes.JSON_UTF8)
@Component
public class SemanticComputingRest {


    private YagoTextsEntityLinker textsEntityLinker;
    private YagoQueryEntityLinker queryEntityLinker;

    public SemanticComputingRest(){
        this.textsEntityLinker = new YagoTextsEntityLinker();
        this.queryEntityLinker = new YagoQueryEntityLinker();
    }

    @GET
    @Path("/_queryentity")
    @Produces(MediaTypes.JSON_UTF8)
    public String  queryEntity(
            @QueryParam("query") String query
    ){
        JsonNode ret = this.queryEntityLinker.getYagoEntityLinkingJson( query );
        return
                JavaToJsonString.mapJavaToJson( ret );
    }


    @GET
    @Path("/_textentity")
    @Produces(MediaTypes.JSON_UTF8)
    public String  textEntity(
            @QueryParam("text") String text
    ){
        JsonNode ret = this.textsEntityLinker.getYagoEntityLinkingJson( text );
        return
                JavaToJsonString.mapJavaToJson( ret );
    }

}
